package alp.starcode.nudtportal;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.boot.web.servlet.ServletComponentScan;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.core.env.Environment;
import org.springframework.scheduling.annotation.EnableAsync;

import java.net.InetAddress;
import java.net.UnknownHostException;


/**
 * 整个项目的入口类
 *
 * @author liwang
 * @date
 */
@Slf4j
@EnableDiscoveryClient
@EnableConfigurationProperties
@SpringBootApplication
@EnableAsync
@ServletComponentScan("alp.starcode.nudtportal.user.*")
public class LayoutPointApplication {

    /**
     * 启动方法
     *
     * @param args
     */
    public static void main(String[] args) {
        ConfigurableApplicationContext application = SpringApplication.run(LayoutPointApplication.class, args);
        //输出日志信息
        outLog(application);
    }

    /**
     * 输出日志
     *
     * @param application
     */
    public static void outLog(ConfigurableApplicationContext application) {
        //启动日志输出
        Environment env = application.getEnvironment();
        String ip = null;
        try {
            ip = InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException e) {
            log.error("获取当前地址信息异常", e);
        }
        String port = env.getProperty("server.port");
        String path = env.getProperty("server.servlet.context-path");
        path = path == null ? "" : path;
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("\n----------------------------------------------------------\n\t");
        stringBuilder.append("Application service is running! Access URLs:\n\t");
        stringBuilder.append("Local: \t\thttp://localhost:").append(port).append(path).append("/\n\t");
        stringBuilder.append("External: \thttp://").append(ip).append(":").append(port).append(path).append("/\n\t");
        stringBuilder.append("Doc: \t\thttp://").append(ip).append(":").append(port).append(path).append("/doc.html\n");
        stringBuilder.append("----------------------------------------------------------");
        log.info(stringBuilder.toString());
    }
}